package com.zr.bookcorner.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.zh.baselibrary.constant.ExtraName;
import com.zh.baselibrary.netutils.HRetrofitNetHelper;
import com.zh.baselibrary.utils.LogUtils;
import com.zh.baselibrary.utils.PhoneUtil;
import com.zr.bookcorner.service.HeartService;
import com.zr.bookcorner.websocket.AppResponseDispatcher;
import com.zr.websocket.WebSocketSend;
import com.zr.websocket.WebSocketService;
import com.zr.websocket.WebSocketSetting;

import org.greenrobot.eventbus.EventBus;

/**
 * @author EnzoChan
 * @create 2019/7/9
 * @desc:
 */
public class ServiceRestartReceiver extends BroadcastReceiver {

    public final static int START_HEART = 1;
    public final static int START_WEB_SOCKET = 3;

    @Override
    public void onReceive(Context context, Intent intent) {
        int restartType = intent.getIntExtra(ExtraName.KEY_DATA, -1);
        if (restartType == START_HEART) {
            context.startService(new Intent(context, HeartService.class));
        } else {
            String uuId = PhoneUtil.getUUID( context);
            WebSocketSetting.setConnectUrl(HRetrofitNetHelper.getWebSocketUrl()+ uuId);//必选
            WebSocketSetting.setResponseProcessDelivery(new AppResponseDispatcher( context));
            WebSocketSetting.setReconnectWithNetworkChanged(true);
            context.startService(new Intent(context, WebSocketService.class));
            EventBus.getDefault().post(new WebSocketSend("","set"));
        }

    }
}
